package ui.activity.mine.presenter;


import com.google.gson.Gson;

import javax.inject.Inject;

import Bean.ComplaintBean;
import Bean.ComplaintParamBean;
import base.BaseBiz;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import ui.activity.mine.biz.ComplaintBiz;
import ui.activity.mine.contract.ComplaintContract;
import util.StringUtils;

/**
 * Created by chenjian on 19/2/26
 */

public class ComplaintPresenter implements ComplaintContract.Presenter {

    ComplaintContract.View view;
    ComplaintBiz complaintBiz;


    @Inject
    public ComplaintPresenter(ComplaintContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        complaintBiz = (ComplaintBiz) biz;
    }


    @Override
    public void setInfo(String id, String complaintInfo) {
        if (StringUtils.isEmpty(complaintInfo)) {
            view.showMsg("请填写建议信息");
            return;
        }
        view.loading(true);
        ComplaintParamBean c = new ComplaintParamBean();
        c.setCustomId(id);
        c.setContent(complaintInfo);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(c));
        complaintBiz.setInfo(requestBody, new BaseBiz.Callback<ComplaintBean.DataBean>() {
            @Override
            public void onSuccess(ComplaintBean.DataBean info) {
                view.loading(false);
                view.showMsg("提交反馈成功");
                view.finishAct();

            }

            @Override
            public void onFailure(ComplaintBean.DataBean info) {
                view.loading(false);
            }
        });
    }


}
